#!/bin/bash
# script name: 银河麒麟容器环境部署脚本
# author: subushi
# update date: 2023.08.02

# 下载麒麟系统 docker 安装包
cd /home
wget https://download.docker.com/linux/static/stable/aarch64/docker-20.10.7.tgz
tar -zxvf docker-20.10.7.tgz


# 移动解压的二进制文件到 /usr/bin 目录
mv docker/* /usr/bin/


# 配置添加 docker 的系统服务文件
cat <<EOF | tee /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP \$MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF


# 赋权重启
chmod +x /usr/lib/systemd/system/docker.service
systemctl daemon-reload


# 导入 docker 配置
mkdir -p /etc/docker

cat <<EOF | tee /etc/docker/daemon.json
{
  "registry-mirrors": ["https://registry.docker-cn.com"],
  "log-opts": {"max-size":"500m", "max-file":"3"},
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF


# 启动 docker
systemctl daemon-reload
systemctl enable --now docker


# 开启核心转发
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p


# 配置银河麒麟网络源
cat <<EOF | tee /etc/yum.repos.d/openEulerOS.repo
[openEuler-source]
name=openEuler-source
baseurl=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/source/
enabled=1
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/source/RPM-GPG-KEY-openEuler

[openEuler-os]
name=openEuler-os
baseurl=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/OS/aarch64/
enabled=1
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/OS/aarch64/RPM-GPG-KEY-openEuler

[openEuler-everything]
name=openEuler-everything
baseurl=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/everything/aarch64/
enabled=1
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/everything/aarch64/RPM-GPG-KEY-openEuler

[openEuler-EPOL]
name=openEuler-epol
baseurl=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/EPOL/aarch64/
enabled=1
gpgcheck=0
EOF

yum clean all
yum makecache


# 安装 docker-compose
yum install docker-compose


# 查看版本信息
docker -v
docker-compose -v
